/**
 * @author: SEKin
 * @Date: 2025-01-13 17:29:03
 * @description:
 * @Last Modified time: 2025-01-13 17:29:03
 */
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import eslint from 'vite-plugin-eslint';
import { resolve, normalize, sep } from 'path';
import progress from 'vite-plugin-progress';
import colors from 'picocolors';
import { visualizer } from 'rollup-plugin-visualizer';

export default defineConfig(({ mode }) => {
  const srcPath = process.cwd();
  const env = loadEnv(mode, resolve(__dirname, 'env'));
  const srcArr = normalize(srcPath).split(sep);
  console.log(env);
  return {
    mode,
    base: `/${srcArr.pop()}`,
    envDir: resolve(__dirname, 'env'),
    build: {
      target: 'esnext',
      outDir: './dist',
      minify: false,
    },
    plugins: [
      vue(),
      vueJsx(),
      eslint({
        // cache: true,
        // emitError: true,
        // emitErrorAsWarning: true,
        // emitWarningAsError: true,
      }), // 需要放最后不然打包会很慢
      progress({
        format: `${colors.green(colors.bold('Bouilding'))} ${colors.cyan(
          '[:bar]'
        )} :percent`,
      }),
      visualizer(),
    ],
    resolve: {},
    server: {
      host: 'localhost',
      open: '/',
      hmr: {
        overlay: true, // 启用：开发服务器错误的屏蔽；这个与vite-plugin-eslint插件配合，形成 发现eslint错误会在项目界面显示错误
      },
    },
  };
});
